package com.annoncesautomobile.vue.affichageannonces;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.annoncesautomobile.R;
import com.annoncesautomobile.vue.utils.ImageLoader;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class PhotosDetailAnnonceAdapter extends BaseAdapter {
	
	private Activity activity;
	private List<String> listPhotos;
	private Map<View, Integer> mapViews;
	private static LayoutInflater inflater = null;
	public ImageLoader imageLoader;
	
	public PhotosDetailAnnonceAdapter(Activity activity, List<String> listPhotos) {
		this.activity = activity;
		this.listPhotos = listPhotos;
		this.mapViews = new HashMap<View, Integer>();
		inflater = (LayoutInflater)this.activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.imageLoader = new ImageLoader(this.activity.getApplicationContext());
	}

	@Override
	public int getCount() {
		return this.listPhotos.size();
	}

	@Override
	public Object getItem(int position) {
		return this.listPhotos.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		String photo = this.listPhotos.get(position);
		View view = inflater.inflate(R.layout.photo_container, null);
		ImageView thumb_image=(ImageView)view.findViewById(R.id.image);
		imageLoader.DisplayImage(photo, thumb_image);
		this.mapViews.put(view, position);
		
		return view;
	}
	
	public int getIndexByView(View view) {
		return this.mapViews.get(view);
	}

}
